// pages/my/my.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    flag:false,
    name:wx.getStorageSync('name'),
    number:wx.getStorageSync('username')
  },

  /**
   * 生命周期函数--监听页面加载
   */

  click(){
    this.setData({
      flag:false
    })
    wx.setStorageSync('flag', this.data.flag)

    // console.log(flag)
    wx.navigateTo({
      url: '../message/message'
    })

  },
   click1(){

     wx.navigateTo({
       url: '../checkshow/checkshow'
     })

   },
   click2(){
    wx.navigateTo({
     url: '../myfix/myfix'
    })

  },
  click3(){
    wx.navigateTo({
     url: '../setting/setting'
    })

  },
  onLoad: function (options) {
    let num=wx.getStorageSync('username');
    console.log(num,123);
    let sname=''
    wx.request({
      url: 'https://yali.geekwhite.cn:3000/message0',
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data: {
        sno:wx.getStorageSync('username'),
        flag:false
      },
      method:'post',
      success:(res)=>{
        console.log(res)
        if(res.data){
          this.setData({
            flag:true
          })
        }
        console.log(this.data.flag)
        if(this.data.flag){
          wx.showTabBarRedDot({
            index: 2,
          })
        }
        else if(!this.data.flag){
          wx.hideTabBarRedDot({
            index: 2,
          })
        }
      }
    })
    wx.request({
      url:'https://yali.geekwhite.cn:3000/sinfor', 
      // header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data: {
        num:num
       },
       method: 'post',
       success: res=>{
          res.data.map((item)=>{
            if(num===item.Sno)
            sname=item.Sname
            this.setData({
              name:sname,
              number:num
            })

          })  
       }
    })
    console.log(this.data.flag)
    // this.setData({
    //   name:wx.getStorageSync('name'),
    //   number:wx.getStorageSync('username')
    // })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let num=wx.getStorageSync('username');
    console.log(num,123);
    let sname=''
    console.log(this.data.flag)
    wx.request({
      url: 'https://yali.geekwhite.cn:3000/message0',
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data: {
        sno:wx.getStorageSync('username'),
        flag:false
      },
      method:'post',
      success:(res)=>{
        // console.log(res)
        if(res.data){
          this.setData({
            flag:true
          })
          wx.setStorageSync('flag', this.data.flag)
        }
        if(this.data.flag){
          wx.showTabBarRedDot({
            index: 2,
          })
        }
        else if(!this.data.flag){
          wx.hideTabBarRedDot({
            index: 2,
          })
        }
        
      }
    })
    wx.request({
      url:'https://yali.geekwhite.cn:3000/sinfor', 
      // header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data: {
        num:num
       },
       method: 'post',
       success: res=>{
          res.data.map((item)=>{
            if(num===item.Sno)
            sname=item.Sname
            this.setData({
              name:sname,
              number:num
            })

          })  
       }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})